<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  function keepTwo(number) {
    return Math.round(number * 100) / 100;
  }

  console.log(keepTwo(0.1 + 0.2));

  // 保留百分比
  function keepPercentage(number) {
    return Math.round(number * 10000) / 100;
  }
</script>

</html>